// pages/brandBusiness/brandBusiness.js
var fileData = require('../../utils/data.js');
var main = require('../../utils/main.js');
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 1,
    imageUrl: app.globalData.imageUrl,
    userInfo: '',
    startPlace: '',
    termini: '',
    banner_url: '',
    advertImg_url: '',
    interval: 3000,
    duration: 1000,
    vertical: false,
    indicatordots: true,
    bottabData: app.globalData.bottabDataForPpsj,
    autoplay: true,
    indicatored: '#F08631',
    indicator: '#fff',
    isShop:'',
    navTopItems: [
      { id: 1, icon: app.globalData.imageUrl + 'ic_gastronomy@2x.png', title: '美食', url: '/pages/hotSeach/hotSeach' },
      { id: 2, icon: app.globalData.imageUrl + 'ic_hotel@2x.png', title: '酒店', url: '/pages/hotSeach/hotSeach' },
      { id: 3, icon: app.globalData.imageUrl + 'ic_fallow@2x.png', title: '休闲娱乐', url: '/pages/hotSeach/hotSeach' },
      { id: 4, icon: app.globalData.imageUrl + 'ic_lido@2x.png', title: '丽人美发', url: '/pages/hotSeach/hotSeach' },
      { id: 5, icon: app.globalData.imageUrl + 'ic_pet@2x.png', title: '宠物', url: '/pages/hotSeach/hotSeach' },
      { id: 6, icon: app.globalData.imageUrl + 'ic_maternal_and_infant@2x.png', title: '母婴', url: '/pages/hotSeach/hotSeach' },
      { id: 7, icon: app.globalData.imageUrl + 'ic_wedding_photography@2x.png', title: '结婚摄影', url: '/pages/hotSeach/hotSeach' },
      { id: 8, icon: app.globalData.imageUrl + 'ic_sports@2x.png', title: '运动健身', url: '/pages/hotSeach/hotSeach' },
      { id: 9, icon: app.globalData.imageUrl + 'ic_auto_service@2x.png', title: '汽车服务', url: '/pages/hotSeach/hotSeach' },
      { id: 10, icon: app.globalData.imageUrl + 'ic_domestic_outfit_building_materials@2x.png', title: '家装建材', url: '/pages/hotSeach/hotSeach' },
      { id: 11, icon: app.globalData.imageUrl + 'ic_education_and_training@2x.png', title: '教育培训', url: '/pages/hotSeach/hotSeach' },
      { id: 12, icon: app.globalData.imageUrl + 'ic_costume@2x.png', title: '服装鞋帽', url: '/pages/hotSeach/hotSeach' },
      { id: 13, icon: app.globalData.imageUrl + 'ic_freight_moving@2x.png', title: '货运搬家', url: '/pages/hotSeach/hotSeach' },
      { id: 14, icon: app.globalData.imageUrl + 'ic_homemaking@2x.png', title: '家政', url: '/pages/hotSeach/hotSeach' },
      { id: 15, icon: app.globalData.imageUrl + 'ic_Industry_resources@2x.png', title: '更多', url: '/pages/hotSeach/hotSeach' }
    ],
    navTopdotItems: [{ current: true }, { current: false }],
    curNavId: 1,
    curIndex: 0,
    colors: ["green", "yellow", "bule", "red"],
    focus: '',
    advert_url: '',
    actiItemHot: [],
    actiItemNew: [],
    current: '1',
    isHot:true,
    current_tel:'',
    loadSuccess: false
  },
  onSlideChangeEnd: function (e) {
    var that = this;
    that.setData({
      current: e.detail.current + 1
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      ['bottabData[0].current']: true,
      userInfo: JSON.parse(wx.getStorageSync('userInfo'))
    })
    fileData.getAdvertData.apply(this, ['4', 'advert_url']);
    this.getBannerData('4', 'top', 0, 'banner_url');
    this.getBannerData('4', 'top', 1, 'advertImg_url');
    this.getbusinesshotList();
    this.getbusinessnewList();
    wx.showLoading()
  },
  enterDesk: function () {
    wx.navigateTo({
      url: '/pages/infoDesk/infoDesk?index=4',
    })
  },
  getIsShop: function(){
    var id = JSON.parse(wx.getStorageSync('userInfo')).id;
    var _this = this;
    wx.request({
      url: app.globalData.httpApiCar + 'shopInfo/getOne',
      data: {
        userId: id
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        
        if (!res.data.success) {
          wx.setStorageSync('isShop', '0');
          wx.removeStorageSync('ShopId');
        }
        else {
          wx.setStorageSync('isOut', res.data.data.dateFlag);
          if (res.data.data.data.status == 1) {
            wx.setStorageSync('isShop', '2');
          }
          else {
            wx.setStorageSync('isShop', '1');
            wx.setStorageSync('ShopId', res.data.data.data.id);
          }
        }
        _this.setData({
          isShop: wx.getStorageSync("isShop")
        })
      }
    })
  },
  getBannerData: function (block, position, type, key) {
    var _this = this;
    wx.request({
      url: app.globalData.httpApiCar + 'tGyImg/getImgsByParams',
      data: {
        block: block,
        position: position,
        type: type
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        if (res.data.success) {
          _this.setData({
            [key]: res.data.data
          })
        }
      }
    })
  },
  // 分类跳转
  switchTap: function(e){
    var item = e.currentTarget.dataset.item;
    wx.navigateTo({
      url: item.url+'?title='+item.title+'&id='+item.id
    })
  },
  openList: function () {
    wx.navigateTo({
      url: '/pages/hotSeach/hotSeach?title=品牌商家&id=null'
    })
  },
  // 商家店铺列表热门
  getbusinesshotList: function () {
    var _this = this;
    wx.request({
      url: app.globalData.httpApiCar + 'shopInfo/getHotShopInfo',
      data: {},
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {  
        _this.setData({
          loadSuccess: true
        })
        wx.hideLoading()
        if(res.data.success){
          _this.setData({
            actiItemHot: res.data.data
          })
        }
      }
    })
  },
  // 商家店铺列表新入
  getbusinessnewList: function () {
    var _this = this;
    wx.request({
      url: app.globalData.httpApiCar + 'shopInfo/all',
      data: {
        // currentPage: this.data.page,
        // pageNumber: '10'
        status:2
      },
      header: {
        'content-type': 'application/json' // 默认值
      },
      success: function (res) {
        _this.setData({
          actiItemNew: res.data.data
        })


      }
    })
  },
  // 打电话
  toggleSelect: function (e) {
    var show = e.currentTarget.dataset.value == "true" ? true : false;
    this.setData({
      showSelect: show,
      current_tel: e.currentTarget.dataset.tel
    })
  },
  callPhone: function (e) {
    wx.makePhoneCall({
      phoneNumber: e.currentTarget.dataset.value 
    })
    this.setData({
      showSelect: false
    })
  },
  intervalChange:function(e){
    this.data.navTopdotItems.forEach(function(ele){
      ele.current=false;
    })
    this.data.navTopdotItems[e.detail.current].current = true;
    this.setData({
      navTopdotItems:this.data.navTopdotItems
    })
    
  },
  switchBotab(e){
    let isShop = wx.getStorageSync("isShop");
    let isOut = wx.getStorageSync("isOut"); 
    if (isShop == 1 && e.currentTarget.dataset.value == '入驻') {
      if (isOut == 1){
        wx.showModal({
          title: '提示',
          content: '您的店铺已到期，请续费',
          showCancel: false,
          success: function (res) {
            if (res.confirm) {
              wx.navigateTo({
                url: '/pages/shopIndex/shopIndex?whole=1'
              })
            }
          }
        })
      }
      else{
        wx.navigateTo({
          url: '/pages/sjwppublish/sjwppublish'
        })
      }
      
    }
    else if (isShop == 2 && e.currentTarget.dataset.value == '入驻') {}
    else{
      wx.navigateTo({
        url: e.currentTarget.dataset.url
      })
    }
  },
  // 打开商家页面
  openIndex(e){
    var id = e.currentTarget.dataset.id;
    wx.navigateTo({
      url: "/pages/shopIndex/shopIndex?id="+id
    })
  },
  tabSwitch:function(e){//热门新入tab页面切换
    var isHot = e.target.dataset.value == "true" ? true : false;
    this.setData({
      isHot: isHot
    })
  },
  bingfocusFunc: function (e) {
    this.setData({
      focus: 'focus'
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    this.getIsShop();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
    
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})